package com.mowh.multithreading.active.object.active.active.object;

/**
 * @author mowh1gd
 * @create 2023/11/28 15:59
 */
class Proxy implements ActiveObject {//代理模式，实际处理工作的是Servant
    private final SchedulerThread scheduler;
    private final Servant servant;

    public Proxy(SchedulerThread scheduler, Servant servant) {
        this.scheduler = scheduler;
        this.servant = servant;
    }

    @Override
    public Result<String> makeString(int count, char fillChar) {//并发操作
        FutureResult<String> future = new FutureResult<>();
        scheduler.invoke(new MakeStringRequest(servant, future, count, fillChar));//MakeString和DisplayString两种请求对于Scheduler来说都是请求，请求直接放入队列
        return future;//不等待真正结果直接返回”提货单“futureResult。（future模式）
    }

    @Override
    public void displayString(String s) {//并发操作
        scheduler.invoke(new DisplayStringRequest(servant, s));
    }
}
